<template>
  <div class="content-box">
    <nav-title title="个人及配偶设立信息" />
    <edit-line label="公司名称" v-model="chigu.cCompany"></edit-line>
    <edit-line label="任职情况" v-model="chigu.cHireRzqk"></edit-line>
    <edit-line label="本人持股" v-model="chigu.cHireBrChigu"></edit-line>
    <edit-line label="配偶持股" v-model="chigu.cHirePoChigu"></edit-line>
    <edit-option-line label="与奥克斯业务往来" :vals="ynList" v-model="chigu.cHireIsRealAux"></edit-option-line>
    <div class="btn_region">
      <div class="submit-btn" @click="save">保存</div>
      <div class="remove-btn" @click="remove"> 删除 </div>
    </div>
    <div stype="width:100%;height:30px">&nbsp;</div>
  </div>

</template>

<script>
import CommonUtil from '../../../../components/basic/util'
import EditLine from '../../../../components/basic/EditLine'
import EditOptionLine from '../../../../components/basic/EditOptionLine'
import { getDicItem,saveChigu,delChigu } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
    EditLine, EditOptionLine
  },
  mounted(){
    if(this.$store.state.hid){
      this.chigu.rsHireId = this.$store.state.hid
    }
  },
  data() {
    return {
      chiguDel: {
        rsHireId: '',
        cSeqno:''
      },
      chigu:{
        rsHireId: '',
      },
      ynList: [{value: '是', key: 'Y'},{value: '否', key: 'N'}],
    }
  },
  created() {
    this.getChigu()
  },
  methods: {

    //银行
    save() {
      // if(!CommonUtil.valid(this, this.chigu,"cCompany","请填写公司名称") 
      //   || !CommonUtil.valid(this, this.chigu,"cHireRzqk","请填写任职情况")  
      //   || !CommonUtil.valid(this, this.chigu,"cHireIsRealAux","请选择是否有业务往来")  
      //   ){
      //   return;
      // }
      if(!this.chigu.cCompany&&
        !this.chigu.cHireRzqk&&
        !this.chigu.cHireBrChigu&&
        !this.chigu.cHirePoChigu) {
        this.$vux.alert.show({
          title: '提示',
          content: '请填写至少一个项目'
        })
        return;
      }
    
      saveChigu(json2Form(this.chigu)).then(res => {
        const that = this;
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          // 显示
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })
        }

        }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })

    },
    remove(){
      const that = this;
      that.$vux.confirm.show({
          // 组件除show外的属性
          title: '提示',
          content: '确定删除？',
          onCancel () {
          },
          onConfirm () {
            delChigu(json2Form(that.chigu)).then(res=>{
              //成功：000000
              if(res && res.retCode === '000000' ){
                  that.$router.push('/informationCollection/userInfo');
              }else{
                // 显示
                that.$vux.alert.show({
                  title: '提示',
                  content: res.retMsg
                })
              }
            })
            .catch(res=>{
              that.$vux.alert.show({
                title: '',
                content: '网络异常，请稍后重试'
              })
            })
          }
        })

    },
    getChigu() {
      if(this.$route.params.chigu){
        this.chigu = this.$route.params.chigu
        this.chiguDel.cSeqno = this.$route.params.chigu.cSeqno
        console.log(this.chigu)
      }
    }
  }
}
</script>
<style type="text/scss" lang="scss">
  @import "./editinfo";
</style>
